/* License Notice:
**
** This program is free software: you can redistribute it and/or modify
**    it under the terms of the GNU General Public License as published by
**    the Free Software Foundation, either version 3 of the License, or
**    (at your option) any later version.
** This program is distributed in the hope that it will be useful,
**   but WITHOUT ANY WARRANTY; without even the implied warranty of
**   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
**   GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
**   along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
 * @file demo_level_background.cpp
 * @author TooOld2Rock'nRoll
 * @see demo_level_background.hpp
 */
/*---- Includes ----*/
#include "demo_level_background.hpp"
#include "demo_level_config.h"

#include "toolbox/debug.h"


/*---- Global Variables ----*/


/*---- Methods Implementation ----*/
/**
 * @brief DemoLevelBackground Base Constructor.
 *
 * @param domain_id - the domain identification to use when loading resources.
 * @param sh - reference to Shader to be used on all render operations.
 */
DemoLevelBackground::DemoLevelBackground (DomainID_t domain_id, Shader *sh) : Scenery(domain_id, sh, TILE_COUNT)
{
    _debug (TRACE, "::%s (domain_id=%u)", __FUNCTION__, domain_id);
}//End Constructor


/**
 * @brief Things that can be loaded inside a working thread
 */
void DemoLevelBackground::load ()
{
    //set sprites to use the correct tiles from texture map
    this->setTexture (this->p_resource_manager->getTexture (this->_res_domain_id, "res/img/background/the_dawn/the_dwan.png")); //set the texture to be used by the GameObject
}//End load ()


void DemoLevelBackground::init ()
{
    Sprite2D *sprites = this->getSprites (); //get the list of Sprites to map individually
    Texture *tex = sprites[0].getTexture (); //all sprites use the same texture...

    _debug (TRACE, "::%s ()", __FUNCTION__);

    if (!tex->getTileMap ())
    {
        tex->createTileMap (TILE_COUNT);
        tex->mapTileBySize (0, 0, 0,    1980, 1080); //background
        tex->mapTileBySize (1, 0, 1090, 1980, 1114); //sun
        tex->mapTileBySize (2, 0, 2214, 1980, 915);  //pine forest
        tex->mapTileBySize (3, 0, 3139, 1980, 766);  //pine forest
        tex->mapTileBySize (4, 0, 3915, 1980, 950);  //pine forest
        tex->mapTileBySize (5, 0, 4875, 1980, 1115); //fog
        tex->mapTileBySize (6, 0, 5999, 1980, 290);  //ground
        tex->mapTileBySize (7, 0, 6299, 1870, 615);  //trees
    }//end if (tex->getTileMap ())

    sprites[0].cropUsingTxTileMap (0, true);
    sprites[0].getPosition().set (0.f, 0.f);
    sprites[1].cropUsingTxTileMap (1, true);
    sprites[1].getPosition().set (0.f, -17.f);
    sprites[2].cropUsingTxTileMap (2, true);
    sprites[2].getPosition().set (0.f, 0.f);
    sprites[3].cropUsingTxTileMap (3, true);
    sprites[3].getPosition().set (0.f, 220.f);
    sprites[4].cropUsingTxTileMap (4, true);
    sprites[4].getPosition().set (0.f, 130.f);
    sprites[5].cropUsingTxTileMap (5, true);
    sprites[5].getPosition().set (0.f, -17.f);
    sprites[6].cropUsingTxTileMap (6, true);
    sprites[6].getPosition().set (0.f, 790.f);
    sprites[7].cropUsingTxTileMap (7, true);
    sprites[7].getPosition().set (5.f, 327.f);
}//End init ()


/**
 * @brief Animates the background.
 *
 * @param delta_t - time elapsed since last game loop iteration.
 */
void DemoLevelBackground::update (double delta_t)
{
}//end update ()

